/*
 * Copyright 2008 Lucifer Lu
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Windows.Shapes;
using SilverChart.Core.Resources;
using SilverChart.Core.Configuration;
using System.Windows.Media;
using System.Windows;

namespace SilverChart.Configuration {
    /// <summary>
    /// Description of AxisBase.
    /// </summary>
    public abstract class AxisBase : AbstractConfigurationItem {
        public const String ITEM_NAME_COLOR = "color";
        public readonly static Color DefaultAxisColor = System.Windows.Media.Color.FromArgb(0xFF, 0x78, 0x40, 0x16); //"#784016"
        private ValueItemHelper<Brush> color;

        public const String ITEM_NAME_THICHNESS = "thickness";
        public const Double DefaultAxisThickness = 2.0d;
        private ValueItemHelper<Double> thichness;

        public const String ITEM_NAME_LABELS = "labels";
        public const String ITEM_NAME_LABELS_ELEMENT = "labels";
        public const Boolean CreateDefaultLabelsArray = true;
        private ValueItemHelper<IList<String>> labels;

        public const String ITEM_NAME_LABELCOLOR = "label_color";
        public readonly static Color DefaultLabelColor = Colors.Black;
        private ValueItemHelper<Brush> labelColor;

        public const String ITEM_NAME_STEP = "step";
        public const Int32 DefaultLabelStep = 1;
        private ValueItemHelper<Int32> step;

        public const String ITEM_NAME_MINORTICKHEIGHT = "minor_tick_height";
        public const Double DefaultMinorTickHeight = 2;
        private ValueItemHelper<Double> minorTickHeight;

        public const String ITEM_NAME_MINORTICKCOLOR = "minor_tick_color";
        public readonly static Color DefautlMinorTickColor = System.Windows.Media.Color.FromArgb(0xFF, 0x78, 0x40, 0x16);//"#784016"
        private ValueItemHelper<Brush> minorTickColor;

        public const String ITEM_NAME_MINORTICKTHICKNESS = "minor_tick_thickness";
        public const Double DefaultMinorTickThickness = 1;
        private ValueItemHelper<Double> minorTickThickness;

        public const String ITEM_NAME_MAJORTICKHEIGHT = "major_tick_height";
        public const Double DefaultMajorTickHeight = 4;
        private ValueItemHelper<Double> majorTickHeight;

        public const String ITEM_NAME_MAJORTICKCOLOR = "major_tick_color";
        public readonly static Color DefautlMajorTickColor = System.Windows.Media.Color.FromArgb(0xFF, 0x78, 0x40, 0x16); //"#784016"
        private ValueItemHelper<Brush> majorTickColor;

        public const String ITEM_NAME_MAJORTICKTHICKNESS = "major_tick_thickness";
        public const Double DefaultMajorTickThickness = 2;
        private ValueItemHelper<Double> majorTickThickness;

        public const String ITEM_NAME_MINORAXISGRID = "show_minor_grid";
        public const Boolean DefaultMinorAxisGrid = true;
        private ValueItemHelper<Boolean> minorAxisGrid;

        public const String ITEM_NAME_MINORGRIDCOLOR = "minor_grid_colour";
        public readonly static Color DefaultMinorGridColor = System.Windows.Media.Color.FromArgb(0x33, 0xF6, 0xEC, 0xC1);//"#33F6ECC1"
        private ValueItemHelper<Brush> minorGridColor;

        public const String ITEM_NAME_MINORGRIDTHICKNESS = "minor_grid_thickness";
        public const Double DefaultMinorGridThickness = 1;
        private ValueItemHelper<Double> minorGridThickness;

        public const String ITEM_NAME_MAJORAXISGRID = "show_major_grid";
        public const Boolean DefaultMajorAxisGrid = true;
        private ValueItemHelper<Boolean> majorAxisGrid;

        public const String ITEM_NAME_MAJORGRIDCOLOR = "major_grid_colour";
        public readonly static Color DefaultMajorGridColor = System.Windows.Media.Color.FromArgb(0x88, 0xF6, 0xEC, 0xC1);//"#88F6ECC1"
        private ValueItemHelper<Brush> majorGridColor;

        public const String ITEM_NAME_MAJORGRIDTHICKNESS = "major_grid_thickness";
        public const Double DefaultMajorGridThickness = 2;
        private ValueItemHelper<Double> majorGridThickness;

        public AxisBase(ConfigurationParser parser)
            : base(parser) {
            color = new BrushValueItemHelper(this, ITEM_NAME_COLOR, DefaultAxisColor);
            thichness = new SimpleValueItemHelper<Double>(this, ITEM_NAME_THICHNESS, DefaultAxisThickness);

            labels = new ArrayValueItemHelper<String>(this, ITEM_NAME_LABELS, ITEM_NAME_LABELS_ELEMENT, CreateDefaultLabelsArray);

            labelColor = new BrushValueItemHelper(this, ITEM_NAME_LABELCOLOR, DefaultLabelColor);
            step = new SimpleValueItemHelper<Int32>(this, ITEM_NAME_STEP, DefaultLabelStep);

            minorTickHeight = new SimpleValueItemHelper<Double>(this, ITEM_NAME_MINORTICKHEIGHT, DefaultMinorTickHeight);
            minorTickColor = new BrushValueItemHelper(this, ITEM_NAME_MINORTICKCOLOR, DefautlMinorTickColor);
            minorTickThickness = new SimpleValueItemHelper<Double>(this, ITEM_NAME_MINORTICKTHICKNESS, DefaultMinorTickThickness);

            majorTickHeight = new SimpleValueItemHelper<Double>(this, ITEM_NAME_MAJORTICKHEIGHT, DefaultMajorTickHeight);
            majorTickColor = new BrushValueItemHelper(this, ITEM_NAME_MAJORTICKCOLOR, DefautlMajorTickColor);
            majorTickThickness = new SimpleValueItemHelper<Double>(this, ITEM_NAME_MAJORTICKTHICKNESS, DefaultMajorTickThickness);

            minorAxisGrid = new SimpleValueItemHelper<Boolean>(this, ITEM_NAME_MINORAXISGRID, DefaultMinorAxisGrid);
            minorGridColor = new BrushValueItemHelper(this, ITEM_NAME_MINORGRIDCOLOR, DefaultMinorGridColor);
            minorGridThickness = new SimpleValueItemHelper<Double>(this, ITEM_NAME_MINORGRIDTHICKNESS, DefaultMinorGridThickness);

            majorAxisGrid = new SimpleValueItemHelper<Boolean>(this, ITEM_NAME_MAJORAXISGRID, DefaultMajorAxisGrid);
            majorGridColor = new BrushValueItemHelper(this, ITEM_NAME_MAJORGRIDCOLOR, DefaultMajorGridColor);
            majorGridThickness = new SimpleValueItemHelper<Double>(this, ITEM_NAME_MAJORGRIDTHICKNESS, DefaultMajorGridThickness);
        }


        public Brush Color { get { return color.Value; } }
        public Double Thickness { get { return thichness.Value; } }

        public IList<String> Labels { get { return labels.Value; } }
        public Brush LabelColor { get { return labelColor.Value; } }
        public Int32 Step { get { return step.Value; } }

        public Double MinorTickHeight { get { return minorTickHeight.Value; } }
        public Brush MinorTickColor { get { return minorTickColor.Value; } }
        public Double MinorTickThickness { get { return minorTickThickness.Value; } }

        public Double MajorTickHeight { get { return majorTickHeight.Value; } }
        public Brush MajorTickColor { get { return majorTickColor.Value; } }
        public Double MajorTickThickness { get { return majorTickThickness.Value; } }

        public Boolean MinorAxisGrid { get { return minorAxisGrid.Value; } }
        public Brush MinorGridColor { get { return minorGridColor.Value; } }
        public Double MinorGridThickness { get { return minorGridThickness.Value; } }

        public Boolean MajorAxisGrid { get { return majorAxisGrid.Value; } }
        public Brush MajorGridColor { get { return majorGridColor.Value; } }
        public Double MajorGridThickness { get { return majorGridThickness.Value; } }

        public Path AxisLine { get { return CreatePath(Color, Thickness); } }
        public Path MinorTickLine { get { return CreatePath(MinorTickColor, MinorTickThickness); } }
        public Path MajorTickLine { get { return CreatePath(MajorTickColor, MajorTickThickness); } }
        public Path MinorGridLine { get { return CreatePath(MinorGridColor, MinorGridThickness); } }
        public Path MajorGridLine { get { return CreatePath(MajorGridColor, MajorGridThickness); } }

        public TextBlock LabelText {
            get {
                TextBlock text = new TextBlock();
                text.Foreground = LabelColor;
                text.HorizontalAlignment = HorizontalAlignment.Left;
                return text;
            }
        }

        private Path CreatePath(Brush strock, Double strokThickness) {
            Path path = new Path();
            path.Stroke = strock;
            path.StrokeThickness = strokThickness;
            return path;
        }

        private const String _LabelText = "AxisLabelText";
    }
}
